import {ProColumns, ProTable} from "@ant-design/pro-components";
import {MpInfoVO, getMpInfoPage, removeMpInfo} from "@/services/MpInfoService";
import {Button, Popconfirm, Space} from "antd";
import React from "react";
import {useAccess, useModel} from "@@/exports";
import {MpInfoModel} from "@/models/mpInfo";

export interface MpInfoProps {
    tableRef?: any;
}


const MpInfoTable = (props: MpInfoProps) => {
    const access = useAccess()
    let {actions: notifyActions} = MpInfoModel

    let {getDictData,getDictEnum} = useModel("dict");


    /**
    * 列定义
    */
    const columns: ProColumns<MpInfoVO>[] = [
        {
            title: "id",
            dataIndex: "id",
            width: 120,
            hideInSearch:true,
        },
        {
            title: "token",
            dataIndex: "token",
            width: 120,
            hideInSearch:true,
        },
        {
            title: "aes_key",
            dataIndex: "aesKey",
            width: 120,
            hideInSearch:true,
        },
        {
            title: "租户id",
            dataIndex: "tenantId",
            width: 120,
            hideInSearch:true,
        },
        {title: '操作', render: (_: any, record: MpInfoVO) => [
        <Space key="operate">
            {access.hasMpInfoUpdatePerm && <Button type="link" size="small" onClick={() => notifyActions.openUpdateModal(true, record)}>编辑</Button>}
            {access.hasMpInfoUpdatePerm && <Popconfirm
                title="确定要删除吗"
                onConfirm={() => {
                    removeMpInfo(record.id).then(() => props.tableRef?.current?.resetFields())
                }}
                okText="确认"
                cancelText="取消"
            >
                <Button type="link" danger size="small">删除</Button>
            </Popconfirm>}
        </Space>
        ],
        hideInSearch: true,
        }
    ]

    // 工具栏
    let actions = [
    access.hasMpInfoSavePerm && <Button key="create" type="primary" onClick={() => notifyActions.openUpdateModal(true, undefined)}>添加</Button>
    ]

    return <>
        <ProTable
                actionRef={props.tableRef}
                columns={columns}
              request={getMpInfoPage}
              toolbar={{
                actions: actions
              }}
                scroll={{x: 500}}
                sticky={{offsetHeader: 55, offsetScroll: 5}}
        >
        </ProTable>
    </>
}

export default MpInfoTable
